﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package GameMode {
    import flash.events.*;
    import Events.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import __AS3__.vec.*;
    import Display.*;
    import Classes.doobers.*;
    import Modules.storage.*;
    import Display.PopulationUI.*;

    public class GMEditStore extends GMEdit {

        private static var SEEN_WARNING:Boolean = false;

        private var m_warningResource:MapResource;

        public function GMEditStore(){
            m_uiMode = UIEvent.STORE;
        }
        override protected function isObjectSelectable(_arg1:GameObject):Boolean{
            var _local3:Vector.<StorageId>;
            if (GMEdit.isLocked){
                return (false);
            };
            var _local2:MapResource = (_arg1 as MapResource);
            if (_local2){
                _local3 = Global.player.storageComponent.getValidStorageUnits(_local2);
                if (((_local2.isStorable()) && ((_local3.length == 1)))){
                    return (true);
                };
            };
            return (false);
        }
        override public function enableMode():void{
            super.enableMode();
            m_cursorImage = EmbeddedArt.hud_act_store;
        }
        override public function onMouseUp(_arg1:MouseEvent):Boolean{
            var _local3:Municipal;
            var _local4:PopulationGateDialog;
            var _local5:String;
            var _local6:GenericDialog;
            if (GMEdit.isLocked){
                finishMouseUpEvent();
                return (false);
            };
            if (UI.resolveIfAssetsHaveNotLoaded(DelayedAssetLoader.GENERIC_DIALOG_ASSETS)){
                finishMouseUpEvent();
                return (false);
            };
            var _local2:MapResource = (m_selectedObject as MapResource);
            if (((_local2) && ((_local2 is Municipal)))){
                _local3 = (_local2 as Municipal);
                if ((((Global.world.citySim.getPopulation() > (Global.world.citySim.getPopulationCap() - _local3.getPopulationCapYield()))) || ((Global.world.citySim.getTotalBusinesses() > (Global.world.citySim.getPopulationCap() - (Math.floor(_local3.getPopulationCapYield()) * Global.gameSettings.getNumber("businessLimitByPopulationMax"))))))){
                    _local4 = new PopulationGateDialog(ZLoc.t("Dialogs", "CannotStoreMunicipal"), "PopulationGate");
                    UI.displayPopup(_local4);
                    return (super.onMouseUp(_arg1));
                };
            };
            if (((_local2) && (!(m_dragging)))){
                if ((_local2 is Doober)){
                    _local2.onPlayAction();
                } else {
                    if (((!(SEEN_WARNING)) && (_local2.warnForStorage()))){
                        this.m_warningResource = _local2;
                        _local5 = _local2.warnForStorageMessage();
                        _local6 = new GenericDialog(_local5, "storageWarning", GenericDialogView.TYPE_YESNO, this.warningHandler);
                        UI.displayPopup(_local6);
                    } else {
                        _local2.store();
                    };
                };
            };
            super.onMouseUp(_arg1);
            deselectObject();
            dehighlightObject();
            return (true);
        }
        private function warningHandler(_arg1:GenericPopupEvent):void{
            if (_arg1.button == GenericPopup.YES){
                this.m_warningResource.store();
                SEEN_WARNING = true;
            };
        }

    }
}//package GameMode 
